<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../../include/admincontent.jsp" %>
<div id="location">当前位置：系统信息管理 > 注册用户管理</div>
<div id="Content" class="empty">
</div>
<div id="sy_search" class=" f0f0f0" style="display: inline-block">
    <form id="advanceQueryParam">
        <div style="background-color: #f0f0f0">
            <div class="clearfix more_query_area">
                <div class="query_area_body clearfix">
                    <div class="record_item">
                        <div class="label">身份证号:</div>
                        <div class="content">
                            <div><input type="text" name="ucode"/></div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="label">真实姓名:</div>
                        <div class="content">
                            <div><input type="text" name="uname"/></div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="label width100">是否创建简历:</div>
                        <div class="content">
                            <div><select name="hasresume">
                                <option value="-1">全部</option>
                                <option value="0">是</option>
                                <option value="1">否</option>
                            </select></div>
                        </div>
                    </div>
                    <div class="record_item">
                        <div class="label">状态:</div>
                        <div class="content">
                            <div><select name="ustate">
                                <option value="-1">全部</option>
                                <option value="0">启用</option>
                                <option value="1">禁用</option>
                            </select></div>
                        </div>
                    </div>

                    <div class="record_item">
                        <div class="toolbars">
                            <a id="searchbtn" >
                                <em class="ico16 search_16"></em>
                                <span class="menu_span" title="查询">查询</span>
                            </a>
                            <a id="searchreset">
                                <em class="ico16 refresh_16"></em>
                                <span class="menu_span" title="重置">重置</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div style="overflow:hidden;">
    <div id="div_table" style="bottom: 0px">
        <table class="layui-hide" id="table" lay-filter="memberIndexTable"></table>
    </div>
</div>

<script type="text/html" id="toolbartemplate">
    <a class="layui-btn layui-btn-xs blue-btn" lay-event="ban">禁用</a>
    <a class="layui-btn layui-btn-xs blue-btn" lay-event="pwd">重置密码</a>
    <a class="layui-btn layui-btn-xs blue-btn" lay-event="blacklist">加入黑名单</a>
    <a class="layui-btn layui-btn-xs blue-btn" lay-event="telrenew">手机号更新</a>
</script>
<script type="text/javascript">
    $(document).ready(function () {
        layui.use('table', () => {
            let table = layui.table;
            table.render({
                id: 'memberIndexTable'
                , elem: '#table'
                , height: 'full-100'
                , url: '/member/getmembersLayuiJson' //数据接口
                , title: '用户表'
                , page: true //开启分页
                , method: 'post'
                , cols: [[ //表头
                    {type: 'numbers', title: '序号', fixed: 'left', width: '5%', sort: true}
                    , {field: 'uname', title: '姓名', width: '5%', sort: true, templet: profile}
                    , {field: 'ucode', title: '身份证号', width: '15%', sort: true}
                    , {field: 'uemail', title: '邮箱', width: '15%', sort: true}
                    , {field: 'tel', title: '手机号', width: '10%', sort: true}
                    , {field: 'regtimeS', title: '注册时间', width: '10%', sort: true}
                    , {field: 'lastlogintime', title: '最后登录时间', width: '10%', sort: true}
                    , {field: 'hasresumeS', title: '是否创建简历', width: '5%', sort: true}
                    , {field: 'ustateS', title: '状态', width: '5%', sort: true}
                    , {toolbar: '#toolbartemplate', title: '操作', fixed: 'right', minWidth: '400'}
                ]]
                , where: {
                    ucode: $("input[name='ucode']").val(),
                    uname: $("input[name='uname']").val(),
                    hasresume: $("select[name='hasresume']").val(),
                    ustate: $("select[name='ustate']").val(),
                },
            });

            function profile(d) {
                if (d.hasresumeS === "是") {
                    return "<a target='_blank' href='/Do/SZResume/ViewResumeCardno?cardno=" + d.ucode + "'>" + d.uname + "</a>";
                } else {
                    return d.uname;
                }
            }

            $("#searchbtn").on('click', () => {
                table.reload('memberIndexTable', {
                    where: {
                        ucode: $("input[name='ucode']").val(),
                        uname: $("input[name='uname']").val(),
                        hasresume: $("select[name='hasresume']").val(),
                        ustate: $("select[name='ustate']").val(),
                    }, page: {
                        curr: 1
                    }
                    , done: (res, curr, count) => {
                        tableresize(diff, false)
                    }
                })
            });
            reload = () => {
                table.reload('memberIndexTable');
            }
            document.tablereload = reload;
            table.on('tool(memberIndexTable)', (obj) => {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                if (layEvent === 'ban') {
                    enableuser(data.id);
                } else if (layEvent === 'pwd') {
                    resetpwd(data.id);
                } else if (layEvent === 'blacklist') {
                    Blacklist(data.id);
                } else if (layEvent === 'telrenew') {
                    ChangeUserTel(data.id);
                }
            });

            //重置密码
            function resetpwd(id) {
                layer.confirm('该用户登录密码将会修改成：111111。<br>确定要执行吗？', {
                    btn: ['是', '否']
                }, function () {
                    postAjax('/member/ChangePwdAction?id=' + id, null, function (data) {
                        if (data.state) {
                            // getList();
                            reload();
                        }
                        $.Showmsg(data.Message);
                    });
                    layer.closeAll();
                }, function () {
                    layer.closeAll();
                });
            }

            //禁用/启用
            function enableuser(id) {
                postAjax('/member/EnableAction?id=' + id, null, function (data) {
                    if (data.state) {
                        reload();
                        // getList();
                    }
                    layer.msg(data.Message, {icon: 1});
                });
            }

            //加入黑名单
            function Blacklist(id) {
                openLayer('加入黑名单', '/member/black?id=' + id, '500px', '230px');
            }

            //修改手机号
            function ChangeUserTel(id) {
                var cwinIndex = layer.open({
                    type: 1
                    , title: '警告!' //不显示标题栏
                    , closeBtn: false
                    , area: '500px,300px'
                    , zIndex: 1000
                    , shade: 0.8
                    , id: 'LAY_UserTelChange' //设定一个id，防止重复弹出
                    , btn: ['确认', '取消']
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div style="color:red;">修改手机号将同时更新该身份证号下所有简历手机号！同时会导致应聘者原手机号无法接受短信，请谨慎操作！</div>'

                    , yes: function (index, layero) {
                        openLayer('手机号修改', '/member/ChangeUserTel?id=' + id, '500px', '430px');
                        layer.close(cwinIndex);
                        //form.forms[0].ajaxPost();
                        return false;

                    }

                });
            }

            function tableresize(diff, resizeout = true) {
                let height3 = $("#div_table").height();
                let height4 = $(".layui-table-body.layui-table-main").height();
                let height5 = $(".layui-form.layui-border-box.layui-table-view").height();


                if (resizeout) {
                    $("#div_table").height(height3 - diff);
                }
                $(".layui-table-body.layui-table-main").height(height4 - diff);
                $(".layui-form.layui-border-box.layui-table-view").height(height5 - diff);
            }

            let diff;
            let origin = {};
            $("#combineQuery").on('click', (e) => {


                let style = $("#advanceQueryParam")[0].style;
                if (style.display === 'block') {
                    style.display = 'none';
                    diff = -origin.diff;
                } else {
                    style.display = 'block';
                    if (!origin.diff) {
                        origin.diff = document.documentElement.scrollHeight - document.documentElement.clientHeight;
                    }
                    diff = origin.diff;
                }
                tableresize(diff);
            });
            $("#searchreset").on('click', (e) => {
                document.getElementById("advanceQueryParam").reset();
                $("input[name='deptcode']").val("")
            });
        });

    });


</script>
</body>
</html>